<?php
apf_require_class("Solr_Dao_Base");
class Solr_Dao_IdxRequest extends Solr_Dao_Base{

    public function get_request_webapp_stat($host,$port,$webapp,$date){
        $pdo=$this->get_idxs_pdo();
    	$sql="select avg(select_count) as count_min
    		  from idx_request_webapp
    		  where hostname=?
    		  		and port=?
    		  		and datei=?
    		  		and webapp=?";
    	$stmt=$pdo->prepare($sql);
    	$stmt->execute(array($host,$port,$date,$webapp));
    	$res1=$stmt->fetch();

        unset($stmt);
    	$sql="select select_slow_count as slow_min,
    				 select_count as max_count_min
    		  from idx_request_webapp
    		  where hostname=?
    		  		and port=?
    		  		and datei=?
    		  		and webapp=?
    		  order by select_count desc
    		  limit 1";
    	$stmt=$pdo->prepare($sql);
    	$stmt->execute(array($host,$port,$date,$webapp));
    	$res2=$stmt->fetch();

        $res['count_min']=(float)$res1['count_min'];
        $res['slow_min']=(float)$res2['slow_min'];
        $res['max_count_min']=(float)$res2['max_count_min'];
    	return $res;
    }

    public function get_request_stat($host,$port,$date){
        $pdo=$this->get_idxs_pdo();
    	$sql="select avg(request_times) as count_min
    		  from idx_request
    		  where hostname=?
    		  		and port=?
    		  		and datei=?";
    	$stmt=$pdo->prepare($sql);
    	$stmt->execute(array($host,$port,$date));
    	$res1=$stmt->fetch();

        unset($stmt);
    	$sql="select request_slow as slow_min,
    				 request_times as max_count_min
    		  from idx_request
    		  where hostname=?
    		  		and port=?
    		  		and datei=?
    		  order by request_times desc
    		  limit 1";
    	$stmt=$pdo->prepare($sql);
    	$stmt->execute(array($host,$port,$date));
    	$res2=$stmt->fetch();

    	$res['count_min']=(float)$res1['count_min'];
        $res['slow_min']=(float)$res2['slow_min'];
        $res['max_count_min']=(float)$res2['max_count_min'];
    	return $res;
    }

}